
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\usepackage{pgfplots.assert}

\begin{document}

\makeatletter

{
	\let\lastvalue=\pgfutil@empty
	\pgfplotsforeachentryinCSV{\value}{1,2,3,4,5}{%
		\let\lastvalue\value
	}%
	\pgfplotsassertequalstok{5}{\lastvalue}{}%
}

{
	\let\lastvalue=\pgfutil@empty
	\pgfplotsforeachentryinCSV{\valueA}{1,2,3,4,5,10}{%
		\pgfplotsforeachentryinCSV{\valueB}{\valueA-1,\valueA-2,\valueA-3,\valueA-4,\valueA-5}{%
			\let\lastvalue\valueB
		}%
		\pgfplotsassertequalstok{\valueA-5}{\lastvalue}{}%
	}
	\pgfplotsassertequalstok{10-5}{\lastvalue}{}%
}

{
	\let\lastvalue=\pgfutil@empty
	\pgfplotsforeachentryinCSV{\value}{1,2,3,4,5}{%
		\ifnum\value>2
			\breakforeach
		\fi
		\let\lastvalue\value
	}

	\pgfplotsassertequalstok{3}{\lastvalue}{}%
}%

{
			\def\SPLIT#1-#2\relax{%
				\ifnum#2>2
					\breakforeach
				\fi
			}%
	\let\lastvalue=\pgfutil@empty
	\pgfplotsforeachentryinCSV{\valueA}{1,2,3,4,5,10}{%
		\pgfplotsforeachentryinCSV{\valueB}{\valueA-1,\valueA-2,\valueA-3,\valueA-4,\valueA-5}{%
			\expandafter\SPLIT\valueB\relax
			\let\lastvalue\valueB
		}%
		\pgfplotsassertequalstok{\valueA-3}{\lastvalue}{}%
	}
	\pgfplotsassertequalstok{10-3}{\lastvalue}{}%
}

{
	\let\lastvalue\value
	\pgfplotsforeachungrouped\value in{1,2,...,5}{%
		\let\lastvalue\value
	}%
	\pgfplotsassertequalstok{5}{\lastvalue}{}%
}

{
	\let\lastvalue\value
	\pgfplotsforeachungrouped\value in{1,2,...,5}{%
		\ifnum\value>2
			\breakforeach
		\fi
		\let\lastvalue\value
	}%
	\pgfplotsassertequalstok{3}{\lastvalue}{}%
}

{
	\let\lastvalue\value
	\pgfplotsforeachungrouped\valueA in{1,2,...,10}{%
		\pgfplotsforeachungrouped\value in{1,2,...,5}{%
			\ifnum\value>2
				\breakforeach
			\fi
			\edef\lastvalue{\valueA-\value}%
		}%
		\pgfplotsassertequalstok{\valueA-3}{\lastvalue}{}%
	}%
	\pgfplotsassertequalstok{10-3}{\lastvalue}{}%
}

{
	\let\lastvalue\value
	\pgfplotsforeachungrouped\value in{1,2,...,5,6,7,...,10}{%
		\let\lastvalue\value
	}%
	\pgfplotsassertequalstok{10}{\lastvalue}{}%
}

{
	\let\lastvalue\value
	\pgfplotsforeachungrouped\value in{1,2,...,5,6,7,...,10}{%
		\ifnum\value>2
			\breakforeach
		\fi
		\let\lastvalue\value
	}%
	\pgfplotsassertequalstok{3}{\lastvalue}{}%
}

{
	\let\lastvalue\value
	\pgfplotsforeachungrouped\valueA in{1,2,...,5,6,7,...,20}{%
		\pgfplotsforeachungrouped\value in{1,2,...,5,6,7,...,10}{%
			\ifnum\value>2
				\breakforeach
			\fi
			\edef\lastvalue{\valueA-\value}%
		}%
		\pgfplotsassertequalstok{\valueA-3}{\lastvalue}{}%
	}%
	\pgfplotsassertequalstok{20-3}{\lastvalue}{}%
}
\end{document}
